package com.dq.Week3.day14.homework;



import java.util.*;

;


public class PkBoom {
    //puke种类
    public static final String[] PUKE_TYPE = {"♥", "♠", "♦", "♣"};
    //puke点数
    public static final String[] PUKE_POINT = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "SJOKER", "BJOKER"};
    private ArrayList<Puke> p1=new ArrayList<>();
    private ArrayList<Puke> p2=new ArrayList<>();
    private ArrayList<Puke> p3=new ArrayList<>();
    private ArrayList<Puke> d1=new ArrayList<>();

    public ArrayList<Puke> getP1() {
        return p1;
    }

    public void setP1(ArrayList<Puke> p1) {
        this.p1 = p1;
    }

    public ArrayList<Puke> getP2() {
        return p2;
    }

    public void setP2(ArrayList<Puke> p2) {
        this.p2 = p2;
    }

    public ArrayList<Puke> getP3() {
        return p3;
    }

    public void setP3(ArrayList<Puke> p3) {
        this.p3 = p3;
    }

    public ArrayList<Puke> getD1() {
        return d1;
    }

    public void setD1(ArrayList<Puke> d1) {
        this.d1 = d1;
    }

    //发牌
    public static void drawPuke(List<Puke> list,List<Puke> p1,List<Puke> p2,List<Puke> p3,List<Puke> d1){
        Collections.shuffle(list);
        int remain=list.size();
        LinkedList<Puke>linkedList=new LinkedList<>(list);
        while(remain>3){
            p1.add(linkedList.pop());
            p2.add(linkedList.pop());
            p3.add(linkedList.pop());
            remain=remain-3;
        }
        d1.addAll(linkedList);

    }
    public static void main(String[] args) {
        List<Puke> pukeList = createPukeList();
        System.out.println("puke打乱前:"+pukeList);
        ArrayList<Puke>p1=new ArrayList<>();
        ArrayList<Puke>p2=new ArrayList<>();
        ArrayList<Puke>p3=new ArrayList<>();
        ArrayList<Puke>d1=new ArrayList<>();
        drawPuke(pukeList,p1,p2,p3,d1);
        System.out.println("puke打乱后:"+pukeList);
        Collections.sort(p1,(o1,o2)->o1.getPukeValue()-o2.getPukeValue());
        System.out.println("p1玩家:"+p1);
        Collections.sort(p2,(o1,o2)->o1.getPukeValue()-o2.getPukeValue());
        System.out.println("p2玩家:"+p2);
        Collections.sort(p3,(o1,o2)->o1.getPukeValue()-o2.getPukeValue());
        System.out.println("p3玩家:"+p3);
        Collections.sort(d1,(o1,o2)->o1.getPukeValue()-o2.getPukeValue());
        System.out.println("底牌:"+d1);
        Integer integer = boomCount(p1);
        Integer integer1 = boomCount(p2);
        Integer integer2 = boomCount(p3);
        System.out.println("p1玩家炸的个数:"+integer);
        System.out.println("p2玩家炸的个数:"+integer1);
        System.out.println("p3玩家炸的个数:"+integer2);


    }

    private static Integer boomCount(ArrayList<Puke> player) {
        int count=0;
        HashMap<String,Integer>hashMap=new HashMap<>();
        ArrayList<String>list=new ArrayList<>();
        for (Puke puke : player) {
            list.add(puke.getValue());
        }
        if(list.contains("SJOKER")&&list.contains("BJOKER")){
            count++;
        }
        Object[] array = list.toArray();
        for (int i = 0; i < array.length; i++) {
            if(hashMap.containsKey(array[i])){
                hashMap.put(array[i].toString(), hashMap.get(array[i])+1);
                if(hashMap.get(array[i])==4){
                    count++;
                }
            }   else {
                hashMap.put(array[i].toString(),1);
            }

        }
        System.out.println("玩家统计排数:"+hashMap);

        return count;



    }


    //创建puke
    private static List<Puke> createPukeList() {
        ArrayList<Puke>list=new ArrayList<>();
        for (int i = 0; i < PUKE_POINT.length-2; i++) {
            for (int j = 0; j < PUKE_TYPE.length; j++) {
                list.add(new Puke(PUKE_TYPE[j],PUKE_POINT[i],i));
            }
        }
        list.add(new Puke("","SJOKER",13));
        list.add(new Puke("","BJOKER",14));
        return list;
    }

}